package com.ruoyi.basedocument.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basedocument.domain.BomMaterialgroup;
import com.ruoyi.basedocument.service.IBomMaterialgroupService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 物料分类Controller
 * 
 * @author ruoyi
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/bomcostestimation/basedocument/materialgroup")
public class BomMaterialgroupController extends BaseController
{
    @Autowired
    private IBomMaterialgroupService bomMaterialgroupService;

    /**
     * 查询物料分类列表
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:materialgroup:list')")
    @GetMapping("/list")
    public AjaxResult list(BomMaterialgroup bomMaterialgroup)
    {
        List<BomMaterialgroup> list = bomMaterialgroupService.selectBomMaterialgroupList(bomMaterialgroup);
        return success(list);
    }

    /**
     * 导出物料分类列表
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:materialgroup:export')")
    @Log(title = "物料分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BomMaterialgroup bomMaterialgroup)
    {
        List<BomMaterialgroup> list = bomMaterialgroupService.selectBomMaterialgroupList(bomMaterialgroup);
        ExcelUtil<BomMaterialgroup> util = new ExcelUtil<BomMaterialgroup>(BomMaterialgroup.class);
        util.exportExcel(response, list, "物料分类数据");
    }

    /**
     * 获取物料分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:materialgroup:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(bomMaterialgroupService.selectBomMaterialgroupById(id));
    }

    /**
     * 新增物料分类
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:materialgroup:add')")
    @Log(title = "物料分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BomMaterialgroup bomMaterialgroup)
    {
        return toAjax(bomMaterialgroupService.insertBomMaterialgroup(bomMaterialgroup));
    }

    /**
     * 修改物料分类
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:materialgroup:edit')")
    @Log(title = "物料分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BomMaterialgroup bomMaterialgroup)
    {
        return toAjax(bomMaterialgroupService.updateBomMaterialgroup(bomMaterialgroup));
    }

    /**
     * 删除物料分类
     */
    @PreAuthorize("@ss.hasPermi('bomcostestimation/basedocument:materialgroup:remove')")
    @Log(title = "物料分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(bomMaterialgroupService.deleteBomMaterialgroupByIds(ids));
    }
}
